package com.yphone.ui.my.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.iiordanov.bVNC.event.bVNCEvent;
import com.yphone.ui.dialog.CommSmallLoadingDialog;
import com.yphone.ui.event.MyEvent;
import com.yphone.ui.login.activity.LoginActivity;
import com.yphone.ui.login.manager.LoginManager;
import com.yphone.ui.login.respone.UserInfo;
import com.yphone.ui.main.MainActivity;
import com.yphone.ui.my.activity.MyDevicesActivity;
import com.yphone.ui.pay.activity.PayActivity;
import com.yphone.ui.ysj.view.YSJAddDeviceView;
import com.zzkj.yunphone.R;
import com.yphone.base.BasicFragment;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

public class TabMyFragment extends BasicFragment implements View.OnClickListener {
    private LinearLayout llRoot;
    private View view_my_rla_mdtc;
    private View view_my_rla_gmysj;
    private TextView tv_phone_num;
    private View btn_logout;
    private View ll_top;

    /* access modifiers changed from: protected */
    public void initData() {
        UserInfo info = LoginManager.getInstance().getInfo();
        if (info != null) {
            tv_phone_num.setText(info.phone);
        }
    }

    /* access modifiers changed from: protected */
    public void initListener() {
        view_my_rla_mdtc.setOnClickListener(this);
        view_my_rla_gmysj.setOnClickListener(this);
        btn_logout.setOnClickListener(this);
        ll_top.setOnClickListener(this);
    }

    /* access modifiers changed from: protected */
    public void initView(View view, Bundle savedInstanceState) {
        EventBus.getDefault().register(this);
        this.llRoot = (LinearLayout) view.findViewById(R.id.ll_root);
        view_my_rla_mdtc = view.findViewById(R.id.view_my_rla_mdtc);
        view_my_rla_gmysj = view.findViewById(R.id.view_my_rla_gmysj);
        tv_phone_num = view.findViewById(R.id.tv_phone_num);
        btn_logout = view.findViewById(R.id.btn_logout);
        ll_top = view.findViewById(R.id.ll_top);
        tv_phone_num.setText("请登录");
    }

    /* access modifiers changed from: protected */
    public int getLayout() {
        return R.layout.fragment_my;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.view_my_rla_mdtc:
                if (LoginManager.getInstance().isLogin()) {
                    MyDevicesActivity.toMyDevicesActivity(getContext());
                } else {
                    LoginActivity.toLoginActivity(getContext());
                }
                break;
            case R.id.view_my_rla_gmysj:
                if (LoginManager.getInstance().isLogin()) {
                    PayActivity.toPayActivity(getContext());
                } else {
                    LoginActivity.toLoginActivity(getContext());
                }
                break;
            case R.id.btn_logout:
                LoginManager.getInstance().clearUserInfo();
                EventBus.getDefault().post(new bVNCEvent.UInotifyEvent(true));
                break;
            case R.id.ll_top:
                if (!LoginManager.getInstance().isLogin()){
                    LoginActivity.toLoginActivity(getContext());
                }
                break;
        }
    }

    @Subscribe
    public void onEventMainThread(final bVNCEvent.UInotifyEvent event) {
        if (LoginManager.getInstance().isLogin()){
            UserInfo info = LoginManager.getInstance().getInfo();
            if (info != null) {
                tv_phone_num.setText(info.phone);
            }
        }else {
            tv_phone_num.setText("请登录");
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}